package com.suxin.queue;

import java.util.Comparator;

/**
 * @author Tang
 * @classname DisorderPriorityQueue
 * @description [  ]
 * @date 2021/3/11 20:59
 */
public class DisorderPriorityQueue<E> extends AbstractQueue<E>{

    int size;
    E[] array;

    public DisorderPriorityQueue(int capacity) {
        super(new Comparator<E>() {
            @Override
            public int compare(E o1, E o2) {
                return 0;
            }
        });
        array = (E[]) new Object[capacity];
        this.size = 0;
    }

    @Override
    public void enqueue(E e) {
        array[size++] = e;
    }

    @Override
    public void outqueue() {
        int max = 0;
        for (int i = 1; i < size; i++) {
            if (less(array[max] , array[i])) {
                max = i;
            }
        }
        size--;
        exch(array,max,size);
        array[size] = null;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }
}